package top.boycharse.blog.secruity.handler;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import top.boycharse.blog.bean.Response.BaseResponse;
import top.boycharse.blog.common.WriterHelp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 拒绝访问时，返回没有权限
 */
public class DeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        WriterHelp.write(response, BaseResponse.buildNotPermission());
    }
}
